import random

#  让系统随机产生一个数字
data = random.randint(0,100)

money=5000
count = 0
while money>=500:
    count = count + 1
    a = input("请输入您要猜的数字：")
    a = int(a)
    if a > data:
        print("大了！")
        money = money - 500
        print("扣除500金币，金额剩余：",money)
    elif a < data:
        print("小了！")
        money = money - 500
        print("扣除500金币，金额剩余：",money)
    else:
        print("恭喜猜中了！本轮幸运数字：",data,"，您用了",count,"次机会！")
        money = money + 3000
        print("奖励3000金币，金额剩余：",money)
        again=int(input("是否继续游戏(是：1/否：2)："))
        while again != 1 and again != 2:
             again = int(input("输入错误，请重新输入(是：1/否：2)："))
        if again == 1:
             continue
        else:
            break  # 强制退出
if money == 0:
    print("余额不足，游戏结束")
else:
    print("游戏结束，余额为：",money)